package com.darkpegasus.trillian.ui;

import com.darkpegasus.trillian.parser.LogParser;

import javax.swing.*;
import javax.swing.text.StyledDocument;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;

/**
 * @author alek
 */
public class LogDocumentBuilderTester {


    public static void main(String[] args) throws InvocationTargetException, InterruptedException {
        String logEvents[] = new String[]{
                "<session type=\"start\" time=\"1194374061\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374064\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"%3F\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374070\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"i%20did\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374072\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"u%20didn%27t%20get%20it%3F\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374082\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"lemme%20try%20again\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374099\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"no%3F\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374101\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"nope\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374106\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"maybe%20i%20need%20to%20start%20a%20new%20one\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374299\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"inviting%20me%20from%20the%20toolbar%20of%20this%20window%20will%20open%20a%20new%20one\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374311\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"and%20fill%20in%20with%20my%20name\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374315\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"yes\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374316\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"but%20it%20gives\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374326\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"Error%20when%20creating%20chat%20room%3B%20possible%20invalid%20character%2E\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374329\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"a%20pop%20with%20that\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374332\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"and%20an%20Ok%20button\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374332\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"hehe\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374352\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"yes%20\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374353\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"did%20that\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374360\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374375\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"I%20got%20a%20request%2C%20but%20that%20was%20to%20one%20I%20made\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374376\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"try%20again\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374403\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"everytime%20i%20get%20that%20error\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374407\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"weird\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374415\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"what%27s%20the%20chat%20room%20name%3F\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374425\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"Daem0nsGirl%20Chat364\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374435\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"try%20just%20testchat\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374455\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"no%20error\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374463\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"but%20no%20request%20to%20me\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374481\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"your%20computer%20and%2For%20internet%20connection%20suck\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374488\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"i%27m%20sorry\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374488\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"hehe\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374490\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374495\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"so%20kay\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374514\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"thanks%20though%2C%20I%20should%20have%20enough%20log%20info\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374515\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374518\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"ya\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374521\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"i%20think%20so\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374536\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"leave\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374536\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"my%20mom%20is%20calling%20me\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374536\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374541\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"there%20were%20other%20ppl%20in%20the%20room\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194374541\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374548\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"hehe\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374562\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"%3A%29\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194374565\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"that%20was%20me\"/>",
                        "<session type=\"stop\" time=\"1194374639\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\"/>",
                        "<session type=\"start\" time=\"1194713695\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713703\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hi%20there\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713712\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"could%20you%20set%20your%20status%20to%20away%2C%20then%20set%20it%20back%20again%3F\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194713718\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"ok\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194713719\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"hehe\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713720\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"i%20think%20theres%20a%20case%20I%20didn%27t%20code%20for\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713720\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<status type=\"away\" time=\"1194713727\" medium=\"AIM\" from=\"Daem0nsGirl\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713779\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"okay\"/>",
                        "<message type=\"information_standard\" time=\"1194713779\" medium=\"AIM\" text=\"Auto%2Dresponse%20from%20Daem0nsGirl%3A%20I%20am%20currently%20away%20from%20the%20computer%2E\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713784\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"should%20be%20good\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713784\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>",
                        "<message type=\"incoming_privateMessage\" time=\"1194713787\" medium=\"AIM\" to=\"Daem0nKn1ght\" from=\"Daem0nsGirl\" from_display=\"Daem0nsGirl\" text=\"ok\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713789\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"now%20I%20got%20the%20autoreply\"/>",
                        "<status type=\"online\" time=\"1194713793\" medium=\"AIM\" from=\"Daem0nsGirl\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713804\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"time%20to%20see%20if%20it%20looks%20different%20in%20the%20logs\"/>",
                        "<message type=\"outgoing_privateMessage\" time=\"1194713805\" medium=\"AIM\" to=\"Daem0nsGirl\" from=\"Daem0nKn1ght\" from_display=\"Daem0nKn1ght\" text=\"hehe\"/>"
        };

        LogDocumentBuilder docBuilder = new LogDocumentBuilder();

        for(String event : logEvents){
            docBuilder.addLogEvent(LogParser.parseEvent(event));
        }

        final StyledDocument doc = docBuilder.getDocument();

        EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                frame.add(new JScrollPane(new JTextPane(doc)));

                frame.setSize(640, 480);
                frame.setVisible(true);
            }
        });
    }
}
